package com.tj.bo.trade.server.service.rule;

import com.alibaba.fastjson.JSON;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 最终只取优先级最高的规则作为最终结果
 * Author: Amarendar
 * Date: 2020/8/25 上午9:48
 */
public class RuleResultVO implements Comparable<RuleResultVO> {

    private String productCode;

    /**
     * 优先级 1~无穷大
     * 1最高
     * 默认值先设置为最低
     */
    private Integer priority = Integer.MAX_VALUE;

    /**
     * 规则处理模式 0-互斥 1-聚合
     */
    private Integer mode = 0;

    /**
     * 变动值
     */
    private BigDecimal changeValue = BigDecimal.ZERO;

    /**
     * 规则名称
     */
    private String ruleName;

    /**
     * 变动原因
     */
    private String message = "";

    public RuleResultVO(String productCode, String ruleName) {
        this.productCode = productCode;
        this.ruleName = ruleName;
    }

    public String getProductCode() {
        return productCode;
    }

    public RuleResultVO setProductCode(String productCode) {
        this.productCode = productCode;
        return this;
    }

    public Integer getPriority() {
        return priority;
    }

    public RuleResultVO setPriority(Integer priority) {
        this.priority = priority;
        return this;
    }

    public Integer getMode() {
        return mode;
    }

    public RuleResultVO setMode(Integer mode) {
        this.mode = mode;
        return this;
    }

    public BigDecimal getChangeValue() {
        return changeValue;
    }

    public RuleResultVO setChangeValue(BigDecimal changeValue) {
        this.changeValue = changeValue;
        return this;
    }

    public String getRuleName() {
        return ruleName;
    }

    public RuleResultVO setRuleName(String ruleName) {
        this.ruleName = ruleName;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public RuleResultVO setMessage(String message) {
        this.message = message;
        return this;
    }

    @Override
    public int compareTo(RuleResultVO o) {
        if (this.priority < o.getPriority()) {
            return -1;
        } else if (this.priority > o.getPriority()) {
            return 1;
        } else {
            if (this.changeValue != null && o.getChangeValue() != null
                    && this.changeValue.doubleValue() < o.getChangeValue().doubleValue()) {
                return -1;
            } else {
                return 0;
            }
        }
    }
}
